package com.yunwaikeji.gy_tool_library.utils.http;

import com.yunwaikeji.gy_tool_library.info.GYHttpInfo;
import com.yunwaikeji.gy_tool_library.model.GYBaseModel;

import java.util.HashMap;
import java.util.Map;

public class GYHttpModel<Model extends GYHttpModel<Model>> extends GYBaseModel implements GYHttpInfo {
    public Model model;
    private String url;//地址
    private String requestMethod = RequestMethod.GET;//请求方式，如GET、POST
    private DataType dataType = DataType.QUERY;//数据类型，默认body json
    private final Map<String, Object> headers = new HashMap<>();//头部数据
    private final Map<String, Object> params = new HashMap<>();//身体数据
    private boolean showNoticeOnStart;//准备时是否显示通知
    private boolean showNoticeOnLoading;//加载中是否显示通知
    private boolean showNoticeOnSuccess;//完成时是否显示通知

    public GYHttpModel() {
        this.model = (Model) this;
    }

    public Model getModel() {
        return model;
    }

    public String getUrl() {
        return url;
    }

    public Model setUrl(String url) {
        this.url = url;
        return model;
    }

    public String getRequestMethod() {
        return requestMethod;
    }

    public Model setRequestMethod(String requestMethod) {
        this.requestMethod = requestMethod;
        return model;
    }

    public Model setDataType(DataType dataType) {
        this.dataType = dataType;
        return model;
    }

    public DataType getDataType() {
        return dataType;
    }

    public Model addHeaders(Map<String, Object> headers) {
        this.headers.putAll(headers);
        return model;
    }

    public Model clearHeaders() {
        headers.clear();
        return model;
    }

    public Model setHeaders(Map<String, Object> headers) {
        clearHeaders();
        return addHeaders(headers);
    }

    public Model addHeader(String key, Object value) {
        this.headers.put(key, value);
        return model;
    }

    public Map<String, Object> getHeaders() {
        return headers;
    }

    public Object getHeader(String key) {
        return headers.get(key);
    }

    //
    public Model addParams(Map<String, Object> params) {
        this.params.putAll(params);
        return model;
    }

    public Model clearParams() {
        params.clear();
        return model;
    }

    public Model setParams(Map<String, Object> params) {
        clearParams();
        return addParams(params);
    }

    public Model addParam(String key, Object value) {
        this.params.put(key, value);
        return model;
    }

    public Map<String, Object> getParams() {
        return params;
    }

    public Object getParam(String key) {
        return params.get(key);
    }

    public boolean isShowNoticeOnStart() {
        return showNoticeOnStart;
    }

    public Model setShowNoticeOnStart(boolean showNoticeOnStart) {
        this.showNoticeOnStart = showNoticeOnStart;
        return model;
    }

    public boolean isShowNoticeOnLoading() {
        return showNoticeOnLoading;
    }

    public Model setShowNoticeOnLoading(boolean showNoticeOnLoading) {
        this.showNoticeOnLoading = showNoticeOnLoading;
        return model;
    }

    public boolean isShowNoticeOnSuccess() {
        return showNoticeOnSuccess;
    }

    public Model setShowNoticeOnSuccess(boolean showNoticeOnSuccess) {
        this.showNoticeOnSuccess = showNoticeOnSuccess;
        return model;
    }
}
